package com.xuelang.pipeline.artifact.entry.harborv2;

import com.xuelang.pipeline.artifact.app.harborv2.ProjectService;
import com.xuelang.pipeline.artifact.app.harborv2.request.CreateProjectRequest;
import com.xuelang.pipeline.artifact.app.harborv2.request.ListProjectQuery;
import com.xuelang.pipeline.artifact.app.harborv2.response.ListProjectResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * HarborV2 项目原生接口web服务
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;
    /**
     * 查询项目列表
     *
     * @param query
     * @return
     */
    @GetMapping(value = "/projects", produces = "application/json;charset=utf-8")
    ApiResponseXO<List<ListProjectResponse>> listProject(@ModelAttribute ListProjectQuery query) {
        return projectService.listProject(query);
    }

    /**
     * 创建项目
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/projects", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createProject(@RequestBody @Valid CreateProjectRequest request) {
        return projectService.createProject(request);
    }

    /**
     * 删除项目
     *
     * @param projectNameOrId
     * @return
     */
    @DeleteMapping(value = "/projects/{project_name_or_id}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteProject(@PathVariable("project_name_or_id") String projectNameOrId) {
        return projectService.deleteProject(projectNameOrId);
    }

}
